package com.personal.ifanya.infrastructure.util;

import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

import com.personal.ifanya.infrastructure.util.component.RandomImageGenerator;

public class VerifyCodeService {

	public static class VerificationCodeResult
	{
		private String code;
		private BufferedImage imageCodeStream;
		public String getCode() {
			return code;
		}
		public void setCode(String code) {
			this.code = code;
		}
		public BufferedImage getImageCodeStream() {
			return imageCodeStream;
		}
		public void setImageCodeStream(BufferedImage imageCodeStream) {
			this.imageCodeStream = imageCodeStream;
		}
		
	}
	
	public static String getVerificationCode(OutputStream outputStream)
	{
		VerificationCodeResult result = new VerificationCodeResult();
		
		String code = RandomImageGenerator.random(5);
		
		try {
			RandomImageGenerator.render(code, outputStream, 130, 40);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			return "";
		}
		 
		return code;
	}
	
}
